package com.cy.system;

import android.content.Context;
import android.content.Intent;
import android.provider.Settings;

import com.cy.app.UtilContext;
import com.cy.io.Log;

public class UtilAccessibility {
    public static void jump2AccessibilityServiceSetting(){
        Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        UtilContext.getContext().startActivity(intent);
    }

    /**
     * 判断当前应用的辅助功能服务是否开启
     * @return
     */
    public static boolean isAccessibilitySettingsOn() {
        Context context = UtilContext.getContext();
        int accessibilityEnabled = 0;
        try {
            accessibilityEnabled = Settings.Secure.getInt(context.getContentResolver(),
                    android.provider.Settings.Secure.ACCESSIBILITY_ENABLED);
        } catch (Settings.SettingNotFoundException e) {
            Log.d("wenming", e.getMessage());
        }

        if (accessibilityEnabled == 1) {
            String services = Settings.Secure.getString(context.getContentResolver(),
                    Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
            if (services != null) {
                return services.toLowerCase().contains(context.getPackageName().toLowerCase());
            }
        }
        return false;
    }


}
